package classes.io;

import org.junit.Test;

import java.io.*;

/**
 * 字符流测试
 */
public class FileReaderWriterTest {
    @Test
    public void test() {
        FileReader fileReader = null;
        FileWriter fileWriter = null;
        try {
            fileReader = new FileReader("./src/classes/io/a.txt");  // 读文件字符流
            fileWriter = new FileWriter("./src/classes/io/b.txt");  // 写文件字符流

            char[] buff = new char[1024];
            int len;
            if ((len = fileReader.read(buff)) != 1) {
                fileWriter.write(buff, 0, len);
            }

        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (fileReader != null) {
                try {
                    fileReader.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

            if (fileWriter != null) {
                try {
                    fileWriter.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

        }
    }
}
